<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        li{
            list-style: none;
            line-height: 40px;
            border:1px dashed #333;
        }
        .wrap {
            margin-bottom: 40px;
        }
    </style>
</head>

<body>
    <div id="app">
        <p>
            <button @click="addEle">addEle</button>
            <button @click="delEle">delEle</button>
        </p>
        <p>
            list:{{list}}
        </p>
        <ul>
            <!-- <li v-for="item in list">{{item}}</li> -->
            <!-- <li v-for="(item,index) in list" :data-index="index">{{item}}</li> -->
        </ul>
      

        <table border="1">
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>班级</th>
                <th>语文</th>
                <th>数学</th>
                <th>英语</th>
                <th>总分</th>
            </tr>
            <tr v-for="item in grade">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.class}}</td>
                <td>{{item.chinese}}</td>
                <td>{{item.math}}</td>
                <td>{{item.english}}</td>
                <td>{{item.chinese + item.math + item.english}}</td>
            </tr>
        </table>


        <h2>v-for和对象</h2>
        <ul>
            <!-- <li v-for="val in info">{{val}}</li> -->
            <!-- <li v-for="val,key in info">{{key}}---{{val}}</li> -->
            <li v-for="val,key,index in info">{{index}}---{{key}}---{{val}}</li>
        </ul>
        

        <h2>v-for和数值</h2>
        <ul>
            <!-- <li v-for="item in 100">{{item}}</li> -->
            <li v-for="item,index in 100">{{index}}---{{item}}</li>
        </ul>
        

    </div>
</body>
<script>

    /* 
    var html = ""
    list.forEach((item)=>{
        html +=`<li>${item}</li>`
    })
    ul.innerHTML = html; */

    /* 
        v-for  列表渲染  用于将一个数组/数值/对象渲染为一组列表

        数组:  遍历数组,生成等量的元素放到父元素中,
        语法:  
            item in list      item循环的当前元素  list 源数组
            item,index in list     item循环的当前元素   index循环的当前下标  list 源数组

        对象:  遍历对象,生成等量的元素放到父元素中,
        语法:  
            val in obj      val循环的当前值  obj 源数组
            val,key in list     val循环的当前值   key循环的当前键名  list 源数组
            val,key,index in list     val循环的当前值   key循环的当前键名   index循环的当前下标  list 源数组


        数值:  遍历数值,生成等量的元素放到父元素中,
        语法:  
            item in n      item循环的当前值(从1开始)   n数值
            item,index in n      item循环的当前值(从1开始)   n数值
            

        注意: 
            v-for 遍历数组/对象/数值 => 得到的数据只能在当前元素以及子元素中使用 (文本 / 属性) 
            v-for 也可以使用of语法 同in语法
    
    */
    var vm = new Vue({
        el: "#app",
        data: {
            list: [1, 4, 7, 2, 5, 8, 3, 6, 9, 10],
            info:{
                name:"张三",
                age:18,
                sex:"男",
                height:"177cm",
                weight:"70kg",
            },
            grade: [{
                id:"1",
                name:"张三",
                class:"2401",
                chinese:55,
                math:66,
                english:77
            },{
                id:"1",
                name:"张三",
                class:"2401",
                chinese:55,
                math:66,
                english:77
            },{
                id:"1",
                name:"张三",
                class:"2401",
                chinese:55,
                math:66,
                english:77
            },{
                id:"1",
                name:"张三",
                class:"2401",
                chinese:55,
                math:66,
                english:77
            }]
        },
        methods: {
            addEle() {
                var ele = Math.round(Math.random() * 100); // 随机元素
                this.list.push(ele);
            },
            delEle() {
                var index = Math.floor(Math.random() * this.list.length);
                this.list.splice(index, 1);
            },
            
        }

    })


    console.log(vm);

</script>

</html>